package com.course.business.controller.admin;

import com.course.server.dto.eacherDto;
import com.course.server.dto.PageDto;
import com.course.server.dto.ResponseDto;
import com.course.server.service.eacherService;
import com.course.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/eacher")
public class eacherController {

private static final Logger LOG = LoggerFactory.getLogger(eacherController.class);
public static final String BUSINESS_NAME = "讲师";

@Resource
private eacherService eacherService;

/**
* 列表查询
*/
@PostMapping("/list")
public ResponseDto eacher(@RequestBody PageDto pageDto) {
ResponseDto responseDto = new ResponseDto();
eacherService.list(pageDto);
responseDto.setContent(pageDto);
return responseDto;
}


/**
* 保存，id有值时更新，无值时新增
*/
@PostMapping("/save")
public ResponseDto save(@RequestBody eacherDto eacherDto) {
// 保存校验
            ValidatorUtil.require(eacherDto.getName(), "姓名");
            ValidatorUtil.length(eacherDto.getName(), "姓名", 1, 50);
            ValidatorUtil.length(eacherDto.getNickname(), "昵称", 1, 50);
            ValidatorUtil.length(eacherDto.getImage(), "头像", 1, 100);
            ValidatorUtil.length(eacherDto.getPosition(), "职位", 1, 50);
            ValidatorUtil.length(eacherDto.getMotto(), "座右铭", 1, 50);
            ValidatorUtil.length(eacherDto.getIntro(), "简介", 1, 500);

ResponseDto responseDto = new ResponseDto();
eacherService.save(eacherDto);
responseDto.setContent(eacherDto);
return responseDto;
}

/**
* 删除
*/
@DeleteMapping("/delete/{id}")
public ResponseDto save(@PathVariable String id) {
ResponseDto responseDto = new ResponseDto();
eacherService.delete(id);
return responseDto;
}
}